﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Componnent.Common;

using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IAccountStateService))]
    public class AccountStateService : CoreServiceBase, IAccountStateService
    {

        [Import]
        public IAccountStateRepository AccountStateRepository { get; set; }

        public IQueryable<AccountState> AccountStates
        {
            get { return AccountStateRepository.Entities; }
        }



        public OperationResult Insert(Domain.ViewModels.BasicSet.AccountState.AccountStateModel model)
        {
            var entity = new AccountState
            {
                Id = model.Id,
                Zhang_HZT = model.Zhang_HZT,
                Zhang_TDM = model.Zhang_TDM,
                CreateDT = DateTime.Now,

                ReviseDT = DateTime.Now

            };
            AccountStateRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(Domain.ViewModels.BasicSet.AccountState.AccountStateModel model)
        {
            var entity = new AccountState
            {
                Id = model.Id,
                Zhang_HZT = model.Zhang_HZT,
                Zhang_TDM = model.Zhang_TDM,
                ReviseDT = DateTime.Now
            };
            AccountStateRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var AccountState = AccountStates.FirstOrDefault(t => t.Id == Id);
            AccountState.IsDeleted = true;

            AccountStateRepository.Update(AccountState);
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
